import {goodsRequest} from '@/request'
//1.分类信息的每一条的类型
export interface categoryInfoType {
    id: number;
    name: string;
    category1Id?: number;
    category2Id?: number;
}
//2.分类信息的列表类型
export type categoryListType = categoryInfoType[];
//3. 平台属性值的每一项的类型
export interface attrValueItemType {
    id?: number; //当前属性值的id
    valueName: string; //当前的属性值某个值
    attrId: number | undefined; //当前属性值所在的属性的id
    isEdit?: boolean;
}

//4.平台属性值列表类型
export type attrValueListType = attrValueItemType[];

//5.平台属性某一项的类型
export interface attrItemType {
    id?: number; //当前平台属性的id
    attrName: string; //当前平台属性的名字
    categoryId: number; //固定的当前的category3Id的值
    categoryLevel: number; //固定是3
    attrValueList: attrValueListType; //当前属性的属性值列表
    selectData?: string;//用来收集选中
}

//6.平台属性列表类型
export type attrListType = attrItemType[];


//1. 请求一级分类数据
export const reqCategory1List = () => {
    return goodsRequest.get<null, categoryListType>(`/admin/product/getCategory1`);
};

//2. 请求二级分类数据
export const reqCategory2List = (category1Id: number) => {
    return goodsRequest.get<null, categoryListType>(
        `/admin/product/getCategory2/${category1Id}`
    );
};

//3. 请求三级分类数据
export const reqCategory3List = (category2Id: number) => {
    return goodsRequest.get<null, categoryListType>(
        `/admin/product/getCategory3/${category2Id}`
    );
};

//4.根据3级分类请求当前分类的属性信息列表
export const reqAttrInfoList = (
    category1Id: number,
    category2Id: number,
    category3Id: number
) => {
    return goodsRequest.get<null, attrListType>(
        `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
    );
};

//5.提交新增属性或者修改属性
export const reqAddOrUpdateAttrList = (newAttr: attrItemType) => {
    return goodsRequest.post(`/admin/product/saveAttrInfo`, newAttr);
};

//6. 删除某个属性的请求
export const reqDeleteAttr = (id: number) => {
    return goodsRequest.delete(`/admin/product/deleteAttr/${id}`);
};
